package stack;

import java.util.Stack;

/**
 * 题目：用两个栈实现队列
 * @Author Gavin
 * @date 2022.08.06 15:30
 */
public class stack_3 {
    Stack<Integer> in = new Stack<>();
    Stack<Integer> out = new Stack<>();

    public void push(int node) {
        in.push(node);
    }

    public int pop() throws Exception {
        if (out.isEmpty())
            while (!in.isEmpty())
                out.push(in.pop());

        if (out.isEmpty())
            throw new Exception("queue is empty");

        return out.pop();
    }
}
